﻿import os
import sys

# Настройка вывода ошибок в файл

# Определяется текущая директория

#__dir__ = os.path.dirname(os.path.abspath(__file__))
#path_error = os.path.join(__dir__, "so_test_error.log")

# Вывод ошибок перенаправляется в файл error.log в текущей директории

#sys.stderr = open(path_error, 'a')






class in_omega:
	"This class contains methods and functions to check corresponence of articles to konstrobj"
	#print (in_omega.__doc__)
	#beginning of class suite
	number=None
	found=False
	error=''
	unvcode=None
	prodcode=None
	revision=None
	
	def check(art_id,version_id):
		'''Function returns unvcode from Omega for provided art_id and version_id from Search. 
		USAGE: get_field(art_id <integer>,version_id <integer>)'''
		#beginning of function suite
		#print (check.__doc__)
		conn_pg = pg_driver.connect(user = c_user, password = c_password, host = c_host, port = c_port, database = c_db)
		select_unvcode_from_map_articles = conn_pg.prepare("SELECT unvcode, prodcode, revision FROM so_map_articles WHERE art_id=$1 AND version_id=$2")
		result=select_unvcode_from_map_articles(art_id,version_id)
		
		in_omega.number=len(result)
		
		if len(result)>0:
			in_omega.found=True
			if len(result)==1:
				in_omega.unvcode=result[0].get(0)
				in_omega.prodcode=result[0].get(1)
				in_omega.revision=result[0].get(2)
			else: in_omega.error='Table so_map_articles contains more then 1 entry for this article!!! Will not return unvcode...'
		else: in_omega.error='Table so_map_articles does not contain any entry for this article!!! Will not return unvcode...'
		#end of function suite
		return

#end of class suite

class to_omega:
	"This class contains methods and functions to import articles to omega"
	#print (to_omega.__doc__)
	#beginning of class suite
	number=None
	imported=False
	error=''
	unvcode=None
	prodcode=None
	revision=None
	itemtype=None

	#end of class suite


#Вывод ошибок возвращается "в исходное положение"

#sys.stderr.close()
#sys.stderr = sys.__stderr__